package com.sc.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sc.domain.Floor;
import com.sc.dto.FloorPageDto;
import com.sc.mapper.FloorMapper;
import com.sc.service.FloorService;
import com.sc.vo.FloorPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static cn.hutool.core.date.DateUtil.now;

/**
 * @Description:
 * @Author: Rui
 * @Date: 2024/11/23 15:59
 */
@Service
public class FloorServiceImpl implements FloorService {
    @Autowired
    private FloorMapper floorMapper;

    @Override
    public boolean addFloor(Floor floor) {
        if (floor.getCreateTime()==null){
            floor.setCreateTime(now());
        }
        return floorMapper.addFloor(floor);
    }

    @Override
    public boolean deleteFloor(Integer id) {
        return floorMapper.deleteFloor(id);
    }

    @Override
    public Floor getById(Integer id) {
        return floorMapper.get(id);
    }

    @Override
    public boolean updateFloor(Floor floor) {
        return floorMapper.updateFloor(floor);
    }

    @Override
    public Map<String,Object> PageQuery(FloorPageDto floorPageDto) {
        PageHelper.startPage(floorPageDto.getPageNumber(), floorPageDto.getPageSize());
        Page<FloorPageVo> info=floorMapper.findFloorPage(floorPageDto);
        Map<String,Object> map=new HashMap<>();
        map.put("total",info.getTotal());
        map.put("pageSize",info.getPageSize());
        map.put("pageNumber",info.getPageNum());
        map.put("data",info.getResult());
        return map;
    }

    @Override
    public Map<String, Object> fuzzyQuery(FloorPageDto floorPageDto) {
        PageHelper.startPage(floorPageDto.getPageNumber(), floorPageDto.getPageSize());
        Page<FloorPageVo> info=floorMapper.fuzzyQuery(floorPageDto);
        Map<String,Object> map=new HashMap<>();
        map.put("total",info.getTotal());
        map.put("pageSize",info.getPageSize());
        map.put("pageNumber",info.getPageNum());
        map.put("data",info.getResult());
        return map;
    }

    @Override
    public boolean deleteByList(List<Integer> ids) {
        return floorMapper.deleteByList(ids);
    }

    @Override
    public List<FloorPageVo> get() {
        return floorMapper.select();
    }
}
